import requests

resp = requests.post(url='http://ihrm-test.itheima.net/api/sys/login',
                     headers={'Content-Type': 'application/json'},
                     json={'mobile': '13800000002', 'password': '123456'})

print(resp.json())

token = 'Bearer ' + resp.json().get('data')

json_data = {"username": "尼古拉斯刘能", "mobile": "13978785941", "timeOfEntry": "2021-04-15", "formOfEmployment": 1,
             "workNumber": "9527", "departmentName": "测试部", "departmentId": "1063678149528784896",
             "correctionTime": "2021-04-29T16:00:00.000Z"}

resp = requests.post(url='http://ihrm-test.itheima.net/api/sys/user',
                     headers={'Content-Type': 'application/json', 'Authorization': token},
                     json=json_data)
print(resp.json())

emp_id = resp.json().get('data').get('id')
print('获取的员工id为:', emp_id)
resp = requests.get(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                    headers={'Content-Type': 'application/json', 'Authorization': token})
print(resp.json())

resp = requests.put(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                    headers={'Content-Type': 'application/json', 'Authorization': token},
                    json={"username": "李四"})
print(resp.json())
# 删除员工列表
resp = requests.delete(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                       headers={'Content-Type': 'application/json', 'Authorization': token})
print('删除员工:', resp.json())
# 查询员工列表
resp = requests.delete(url='http://ihrm-test.itheima.net/api/sys/user/:target',
                       headers={'Content-Type': 'application/json', 'Authorization': token})
print('查询员工列表:', resp.json())
